package EnumLearn;


import org.junit.jupiter.api.Test;

/**
 * @author Lenl
 * @version v1.0
 * @create 2021-06-04 15:14
 * @description
 * 一、枚举类的使用
 *  1.理解：类的对象有限个且确定的，称为枚举类
 *  2.当需要定义一组常量时，建议使用枚举类
 *  3.如果枚举类只有一个对象，则可以作为一种单例模式的实现方式
 *
 *二、定义枚举类
 *  1.JDK5.0前自定义枚举类
 *  2.JDK5.0可以使用enum关键字定义枚举类
 */
public class SeasonTest {
    @Test
    public void test(){
        Season season=Season.SPRING;
        System.out.println(season.toString());
        System.out.println(season.getSeasonName());
    }

}

/**
 * 自定义枚举类
 */
class Season{
    //1.声明Season的属性,private final修饰
    private final String seasonName;
    private final String seasonDesc;

    //2.私有化类的构造器
    private Season(String seasonName,String seasonDesc){
        this.seasonName=seasonName;
        this.seasonDesc=seasonDesc;
    }
    //3.提供当前枚举类的多个对象，public static final的
    public static final Season SPRING=new Season("春天","春暖花开");
    public static final Season SUMMER=new Season("夏天","夏日炎炎");
    public static final Season AUTUMN=new Season("春天","秋高气爽");
    public static final Season WINTER=new Season("冬天","冰天雪地");
    //其他诉求：1.获取枚举类的属性


    public String getSeasonName() {
        return seasonName;
    }

    public String getSeasonDesc() {
        return seasonDesc;
    }
    //其他诉求：2.提供toString()方法

    @Override
    public String toString() {
        return "Season{" +
                "seasonName='" + seasonName + '\'' +
                ", seasonDesc='" + seasonDesc + '\'' +
                '}';
    }
}

